package com.example.mybatis.Annotation1;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Test03 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
        Class aClass = Class.forName("com.example.mybatis.Annotation1.User");

        User user =(User)aClass.newInstance();

        Method setName=aClass.getDeclaredMethod("setName", String.class);
        setName.invoke(user,"zhangsan");

        System.out.println(user.getName());
        System.out.println("======================");

        Field age = aClass.getDeclaredField("age");
        age.setAccessible(true);
        age.set(user,18);
        System.out.println(user.getAge());
    }

}
